package problem205;

import java.util.HashMap;
import java.util.Map;

//205.同构字符串
//https://leetcode.cn/problems/isomorphic-strings/?envType=study-plan-v2&envId=top-interview-150
class Solution {
    public boolean isIsomorphic(String s, String t) {
        int n = s.length(); 
        Map<Character, Character> map1 = new HashMap<>();
        Map<Character, Character> map2 = new HashMap<>();
        for(int i = 0; i<n; i++) {
            char c1 = s.charAt(i), c2 = t.charAt(i);
            if(!map1.containsKey(c1)) {
                map1.put(c1, c2);
                if(map2.containsKey(c2) && map2.get(c2) != c1) return false;
                map2.put(c2, c1);
            }else if(map1.get(c1) != c2) return false;

        }
        return true;
    }
}